#include<bits/stdc++.h>
using namespace std;
int T, n, a[200005], t, ans, r, b;
bool ch[200005];
int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    cin>>T;
    while(T--){
        t = 0;
        cin>>n;
        for (int i=0;i<n;i++){
            cin>>a[i];
        }
        ans = 0;
        for (int i=0;i<pow(2, n);i++){
            int res=0;
            int cnt=0;
            t = i;
            while(t>0){
                ch[cnt++] = t%2;
                t /= 2;
            }
            r = b = -1;
            for (int j=0;j<n;j++){
                if (ch[j] == 0){
                    if (r == a[j]){
                        res += r;
                    }
                    else{
                        r = a[j];
                    }
                }
                else if (ch[j] == 1){
                    if (b == a[j]){
                        res += b;
                    }
                    else{
                        b = a[j];
                    }
                }
            }
            ans = max(ans, res);
        }
        cout<<ans<<endl;
    }
}
